#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>

#define NUM 10000

void *worker(void *arg)
{
    double *pi_back = malloc(sizeof(double));
    *pi_back = 0;
    for (int i = NUM / 2 + 1; i <= NUM; i++) {
        double t = 1 / (double)(2 * i -1);
        if (i % 2 == 0) {
            *pi_back -= t;
        }
        else
            *pi_back += t;
    }
    *pi_back *= 4;
    return pi_back;
}

int main()
{
    pthread_t worker_tid;
    pthread_create(&worker_tid, NULL, worker, NULL);
    double pi = 0;
    for (int i = 1; i <= NUM / 2; i++) {
        double t = 1 / (double)(2 * i -1);
        if (i % 2 == 0) {
            pi -= t;
        }
        else
            pi += t;
    }
    pi *= 4;
    double *pi_back;
    pthread_join(worker_tid, (void **)&pi_back);
    pi += *pi_back;
    free(pi_back);
    printf("%f\n", pi);
    return 0;
}
